package Package.Example.MethodOfTheClassGetsTheMemberMethodObjects;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MethodOfTheClassGetsTheMemberMethodObjects {
    public static final void MethodOfTheClassGetsTheMemberMethodObjecs() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> c=Class.forName("Package.Example.GetsTheConstructorAndUses.Student");
//通过反射获取成员方法并调用
        Constructor<?> con=c.getConstructor();
Object obj=con.newInstance();
        Method method1 = c.getMethod("method1");
        System.out.println("+++++++++++++++++++++");
        Object invoke = method1.invoke(obj);
        System.out.println(invoke);
        System.out.println("++++++++++++++++++++++++++++++++++");
        Method method2 = c.getMethod("method2", String.class);
        con.setAccessible(true);
        Object changCun = method2.invoke(obj, "ChangCun");
        System.out.println(changCun);
        System.out.println("++++++++++++++++++++++++++++++++++");
        Method method3 = c.getMethod("method3", String.class, int.class);
        Object chngacun = method3.invoke(obj, "Chngacun", 300);
        System.out.println(chngacun);
        Method function = c.getDeclaredMethod("function");
        function.setAccessible(true);
        Object invoke1 = function.invoke(obj);
        System.out.println(invoke1);


    }
}
